﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;
using Utility;

public partial class ReportUI_R_CheckScore : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindType();
            BindOrgan();
            GridView1.DataBind();
            ddl_Type_SelectedIndexChanged(sender, e);

            InitControl();
        }
    }

    protected void BindType()
    {
        DataTable ds = new ReportBLL().GetReportSort("抽查评分");
        ddl_Type.DataSource = ds;
        ddl_Type.DataTextField = "SortName";
        ddl_Type.DataValueField = "SortID";
        ddl_Type.DataBind();
    }

    protected void BindOrgan()
    {
        DataSet ds = new OrganBLL().GetAllList();
        ddl_Organ.DataSource = ds;
        ddl_Organ.DataTextField = "OrganName";
        ddl_Organ.DataValueField = "OrganID";
        ddl_Organ.DataBind();
    }
    protected void ddl_Type_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddl_Type.SelectedValue.ToString() == "RS014")
        {
            Panel_Car.Visible = false;
            Panel_Time.Visible = true;
            Panel_Organ.Visible = true;
        }
        else
        {
            Panel_Car.Visible = false;
            Panel_Time.Visible = true;
            Panel_Organ.Visible = false;
        }

        InitControl();
    }

    private void InitControl()
    {
        txt_Car.Text = "";
        ddl_Organ.SelectedIndex = 0;
        txt_StartTime.Text = DateTime.Now.Year.ToString() + "-1-1";
        txt_EndTime.Text = DateTime.Now.ToString("yyyy-MM-dd");

        GridView1.DataSource = null;
        GridView1.DataBind();
    }

    protected void btn_Search_Click(object sender, EventArgs e)
    {
        string _sortID = ddl_Type.SelectedValue.ToString();

        Hashtable args = new Hashtable();
        args.Add("OrganID", ddl_Organ.SelectedValue);
        args.Add("Car", txt_Car.Text.Trim());
        args.Add("StartTime", txt_StartTime.Text.Trim());
        args.Add("EndTime", txt_EndTime.Text.Trim());

        ReportBLL bll = new ReportBLL();
        DataTable dtSource = new DataTable();

        dtSource = bll.GetCheckScoreRate(_sortID, args);
        GridView1.DataSource = dtSource;
        GridView1.DataBind();
    }
    protected void btn_Excel_Click(object sender, EventArgs e)
    {
        DataTable dt = GridViewService.GridView2DataTable(GridView1);
        try
        {
            ExcelService.ExportDataTableToExcel(dt, DateTime.Now.ToString("yyyyMMddHHmmss"), "评分");
        }
        catch (Exception ex)
        {
            UtilityService.Alert(this.Page, "导出失败!详细:" + ex.Message);
        }
    }

}
